/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package quizzempire.view;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JFrame;
import quizzempire.model.IModel;
import quizzempire.model.statemachine.AwaitsInstruction;
import quizzempire.model.statemachine.State;

/**
 *
 * @author Victor
 */
public class MainMenu extends JFrame implements Observer{

    /**
     * Creates new form MainMenu
     */
    IModel model;
    
    public MainMenu(IModel model) {
        initComponents();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
        this.model = model;
        model.addObserver(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btEditQuizz = new javax.swing.JButton();
        btCreateQuizz = new javax.swing.JButton();
        btStartQuizz = new javax.swing.JButton();
        btQuitApp = new javax.swing.JButton();
        lbLogo = new javax.swing.JLabel();
        btAbout = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setPreferredSize(new java.awt.Dimension(460, 370));
        setResizable(false);

        btEditQuizz.setText("EDIT A QUIZZ");
        btEditQuizz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditQuizzActionPerformed(evt);
            }
        });

        btCreateQuizz.setText("CREATE A QUIZZ");
        btCreateQuizz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCreateQuizzActionPerformed(evt);
            }
        });

        btStartQuizz.setText("START A QUIZZ");
        btStartQuizz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btStartQuizzActionPerformed(evt);
            }
        });

        btQuitApp.setText("QUIT");
        btQuitApp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btQuitAppActionPerformed(evt);
            }
        });

        lbLogo.setText("LOGO");

        btAbout.setText("?");
        btAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAboutActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(141, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btEditQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btCreateQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btStartQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(137, 137, 137))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btQuitApp, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btAbout, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(119, 119, 119)
                .addComponent(lbLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addComponent(lbLogo, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                .addGap(49, 49, 49)
                .addComponent(btStartQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btCreateQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btEditQuizz, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btQuitApp, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btAbout))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btEditQuizzActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditQuizzActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btEditQuizzActionPerformed

    private void btCreateQuizzActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCreateQuizzActionPerformed
        model.startGame();
    }//GEN-LAST:event_btCreateQuizzActionPerformed

    private void btStartQuizzActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btStartQuizzActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btStartQuizzActionPerformed

    private void btQuitAppActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btQuitAppActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btQuitAppActionPerformed

    private void btAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAboutActionPerformed
        About about = new About(model);
        about.setModal(true);
        about.setVisible(true);
    }//GEN-LAST:event_btAboutActionPerformed
 
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAbout;
    private javax.swing.JButton btCreateQuizz;
    private javax.swing.JButton btEditQuizz;
    private javax.swing.JButton btQuitApp;
    private javax.swing.JButton btStartQuizz;
    private javax.swing.JLabel lbLogo;
    // End of variables declaration//GEN-END:variables

    @Override
    public void update(Observable o , Object arg){
        State state = model.getState(); 
        if (!(state instanceof AwaitsInstruction))
            MainBuilder.changeScreen(this, model, state);
    }
}
